package com.lzx.iteam;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
//import com.lzx.iteam.util.CommonCodeUtil;
import com.lzx.iteam.R;
import com.lzx.iteam.util.PreferenceUtil;

public class FakeDialog extends Activity implements View.OnClickListener{
    
    private Button mOkBtn;
    private Button mCancel;
    private TextView mTitle;
    private TextView mMessage;
    public static final String DIALOG_TITLE = "dialog_title";
    public static final String DIALOG_MESSAGE = "dialog_message";
    public static final String DIALOG_NUMBER = "dialog_number";
    private PreferenceUtil mPreferenceUtil;
    private String mPhoneNumber;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fake_dialog_layout);
        mOkBtn = (Button)findViewById(R.id.positive_btn);
        mCancel = (Button)findViewById(R.id.negative_btn);
        mTitle = (TextView)findViewById(R.id.fake_dialog_title);
        mMessage = (TextView)findViewById(R.id.fake_dialog_message);
        getIntentData();
        mPreferenceUtil = PreferenceUtil.getInstance(this);
        mOkBtn.setOnClickListener(this);
        mCancel.setOnClickListener(this);
    }
    
    private void getIntentData(){
        Intent intent = getIntent();
        String titleText = intent.getStringExtra(DIALOG_TITLE);
        String titleMessage = intent.getStringExtra(DIALOG_MESSAGE);
        mPhoneNumber = intent.getStringExtra(DIALOG_NUMBER);
        mTitle.setText(titleText);
        mMessage.setText(titleMessage);
    }
    
    private static void getDownload(PreferenceUtil preferenceUtil, Context context) throws ActivityNotFoundException{
        String url = preferenceUtil.getString(PreferenceUtil.TWO_SIM_DWONLOAD_URL, null);
        Intent intent = new Intent();
        intent.setData(Uri.parse(url));
        intent.setAction(Intent.ACTION_VIEW);
        context.startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        
        switch (v.getId()) {
            case R.id.positive_btn: 
                try {
                    getDownload(mPreferenceUtil, this);
//                    dialog.dismiss();
                } catch (ActivityNotFoundException e) {
                    //: handle exception
                    Toast.makeText(this, R.string.no_browser, Toast.LENGTH_LONG).show();
                }
                this.finish();
            
                break;
                
//            case R.id.negative_btn:
//                Intent intent = CommonCodeUtil.getCallIntent(mPhoneNumber);
//                startActivity(intent);
//                this.finish();
//                break;

            default:
                break;
        }
        
    }
    
    

}
